package com.perpus;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.*;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

public class Perpustakaan {

    private static String nama = "Perpustakaan Budi Luhur";
    private static ArrayList<Publikasi> daftarPublikasi = new ArrayList<Publikasi>();
    private static ArrayList<Anggota> daftarAnggota = new ArrayList<Anggota>();

    public String getNama() {
        return nama;
    }

    public void setNama(String nama) {
        Perpustakaan.nama = nama;
    }

    public static void tambahPublikasi(Publikasi publikasi) {
        daftarPublikasi.add(publikasi);
    }

    public static void tambahAnggota(Anggota anggota) {
        daftarAnggota.add(anggota);
    }

    public static String bacaPublikasi() {
        return null;
    }

    public static String bacaAnggota() {
        return null;
    }

    public static void simpanFilePublikasi() {
        FileOutputStream outStream = null;
        if (daftarPublikasi.isEmpty()) {
            System.out.println("Daftar Publikasi Kosong");
        } else {
            try {
                File outFile = new File("publikasi.dat");
                outStream = new FileOutputStream(outFile);
                ObjectOutputStream outObjectStream = new ObjectOutputStream(outStream);
                outObjectStream.writeObject(daftarPublikasi);
                outStream.close();
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage());
                Logger.getLogger(Anggota.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public static void bacaFilePublikasi() throws IOException {
        FileInputStream inStream = null;
        File inFile = new File("publikasi.dat");
        inStream = new FileInputStream(inFile);
        ObjectInputStream inObjectStream = new ObjectInputStream(inStream);
        daftarPublikasi = (ArrayList<Publikasi>)
                }
                

    public static void TambahTabelPublikasi(Publikasi publikasi) {
        Connection conn = OraConnection.open("jdbc:oracle:thin:@172.23.9.185:1521:orcl", "MHS115314022", "MHS115314022");
        Statement statement;
        try {
            statement = conn.createStatement();
            String sql = "insert into publikasi (id_koleksi, judul) values ('" + publikasi.getIdKoleksi() + "','" + publikasi.getJudul() +"')";
            statement.executeUpdate(sql);
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(Perpustakaan.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}